"""App configuration."""
###Mysql配置
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
import configparser
import os
from urllib.parse import quote
from utils.path_util import get_root_dir
cf = configparser.ConfigParser()
cf.read(os.path.join(get_root_dir(), "config.ini"))

secs = cf.sections()
host = cf.get("Mysql-Database", "host")
port = cf.get("Mysql-Database", "port")
user = cf.get("Mysql-Database", "user")
password = cf.get("Mysql-Database", "password")
db_name = cf.get("Mysql-Database", "db")

mysql_info = dict(
    host=host,
    port=port,
    dbname=db_name,
    username=user,
    password=password
)
MYSQL_URL = 'mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8' % (mysql_info['username'], quote(mysql_info['password']),
                                                             mysql_info['host'], mysql_info['port'],
                                                             mysql_info['dbname'])


class Config:
    """Prod config."""
    """基础配置，导入所有配置中"""
    # 数据库自动提交数据
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # 如果设置成 True (默认情况)，Flask-SQLAlchemy 将会追踪对象的修改并且发送信号。
    # 这需要额外的内存， 如果不必要的可以禁用它。
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    # apscheduler 配置信息
    JOBS = []
    SCHEDULER_JOBSTORES = {
        'default': SQLAlchemyJobStore(url=MYSQL_URL, tablename='apscheduler_jobs')
    }


class DevelopmentConfig(Config):
    """Dev config."""
    DEBUG = True
